#include "camprec.h"

#include "ConversionUtils.h"

namespace cm
{
	namespace convert
	{

long str2long (const std::wstring &sVal, bool *err)
{	
	wchar_t *p; 
	long res = wcstol (sVal.c_str(), &p, 0);
	if (err){
		if (*p) {
			*err = true;
			return 0;
		}
		else
			*err = false;
	}
	return res;
};
DWORD str2DWORD (const std::wstring &sVal, bool *err)
{
	wchar_t *p;  
	DWORD res = wcstoul (sVal.c_str(), &p, 0);
	if (err){
		if (*p){
			*err = 1;
			return 0;
		}
		else
			err = false;
	}
	if (res < 0)
	{
		*err = true;
		return 0;
	}
	return res;
};

double str2double (const std::wstring &sVal, bool *err)
{
	wchar_t *p; 
	double res = wcstod (sVal.c_str(), &p);
	if (err)
	{
		if (*p) 
		{
			*err = true;
			return 0;
		}
		else
			*err = false;
	}
	return res;
};

	void conv_alglib_real_1d_array2vector (const alglib::real_1d_array &alglib_arr, std::vector<double> &std_v, const bool &base_0)
	{
		//if (base_0)
		//{
			std_v.resize (alglib_arr.length());
			
			for (long i = 0; i < alglib_arr.length(); i++)
				std_v[i] = alglib_arr [i];
		//}
		//else
		//{
		//	for (long i = 0; i < ap_arr.getlowbound (); i++)
		//		std_v.push_back (0);
		//	for (long i = ap_arr.getlowbound (); i<= ap_arr.gethighbound (); i++)
		//		std_v.push_back (ap_arr(i));
		//}
	}
	}

};